package me.xplabs.view 
{
	import flash.display.Bitmap;
	import flash.display.DisplayObjectContainer;
	import flash.events.MouseEvent;
	import me.xplabs.Globals;
	import me.xplabs.model.combatunit.RaidButtonData;
	import me.xplabs.model.GameDataSingleton;
	import me.xplabs.msg.NotificationFloatingBox;
	import me.xplabs.msg.NotificationName;
	import me.xplabs.ui.baseui.Button;
	import me.xplabs.ui.BaseView;
	import me.xplabs.ui.UICompent;
	
	/**
	 * http://www.xplabs.me/
	 * @author xiaohan
	 */
	public class SelecteRaidView extends BaseView 
	{
		private var _backGround:Bitmap;
		
		private var _raidBtns:Vector.<Button>;
		public function SelecteRaidView(pfather:DisplayObjectContainer) 
		{
			super(pfather);
		}
		
		override protected function init():void 
		{
			super.init();
			
			_backGround = new Bitmap();
			_backGround.bitmapData = Globals.lib.getResObj(Globals.domain.texture + 27);
			addChild(_backGround);
			
			_raidBtns = new Vector.<Button>();
			var raids:Vector.<RaidButtonData> = GameDataSingleton.i.raidButtons;
			var len:int = raids.length;
			for (var i:int = 0; i < len; i++)
			{
				var button:Button = Globals.ui.button("", 13);
				button.x = raids[i].x - button.width * .5;
				button.y = raids[i].y - button.height * .5;
				button.index = raids[i].id;
				button.overCall = overRaidHandler;
				button.outCall = outRaidHandler;
				button.callback = clickRaidHandler;
				addChild(button);
				//UICompent.addListener(button);
			}
			
		}
		
		private function clickRaidHandler(e:MouseEvent):void 
		{
			sendMsg(NotificationName.SELECTED_RAID, e.currentTarget.index);
		}
		
		private function outRaidHandler(e:MouseEvent):void 
		{
			sendMsg(NotificationFloatingBox.HIDE_FLOATING_BOX);
		}
		
		private function overRaidHandler(e:MouseEvent):void 
		{
			sendMsg(NotificationFloatingBox.SHOW_RAID_BUTTON, GameDataSingleton.i.getRaidButtonsById(e.currentTarget.index));
		}
	}

}